<template>
  <div v-if="gadgetSetting.show">
    <Portal to="right-disable"
            :disabled="!queryModelDefaultSetting.showSetting">
      <el-form :inline="true">
        <el-form-item v-loading='loading'>
          <el-input v-model="deptId" disabled></el-input>
        </el-form-item>
      </el-form>
    </Portal>
    <model :showSetting="queryModelDefaultSetting.showSetting" @queryModelClosed="queryModelClosed"
           :dataInfo="queryModelDefaultSetting.dataInfo"
           :updateGadget="upgradeGadgetSetting"/>
<!--    :mappingForm="mappingFormSetting"-->
  </div>
</template>

<script>
import mixinGadgetViewModule from '@/mixins/gadget-view-module'
// import model from '@/components/gadget/query-model/query-model.vue'

export default {
  mixins: [mixinGadgetViewModule],
  components: { model: () => import('@/components/gadget/query-model/query-model') },
  data () {
    return {
      mixinViewModuleOptions: {
        pageId: this.pageId
      },
      gadgetStatus: 'init',
      deptId: this.$store.state.user.deptId,
      loading: false,
      gadgetSetting: {},
      queryModelDefaultSetting: {
        showSetting: false,
        dataInfo: {
          businessId: this.pageId,
          gadgetId: this.id,
          gadgetType: 'deptdefaultslicergadget',
          gadgetSettingExclude: ['DATA'],
          gadgetSetting: {
            label: '',
            queryParams: 'deptId',
            show: true
          }
        }
      }

    }
  },
  beforeCreate () {
    // this.$options.components.model = () => import('@/components/gadget/query-model/query-model')
  },
  created () {
    this.query()
    this.publishMessage('runReport')
    this.$store.state.isWidget = false
  },
  watch: {

  },
  methods: {
    resetslicer () {
      this.getDataListParams()
    },
    getDataListParams () {
      var _self = this
      var newslicer = {}
      newslicer[_self.gadgetSetting.queryParams] = this.deptId
      _self._.merge(_self.slicer, newslicer)
    },
    queryModelClosed () {
      this.queryModelDefaultSetting.showSetting = false
      this.query()
    },
    showQueryModel () {
      this.queryModelDefaultSetting.showSetting = true
    },
    query () {
      this.loading = true
      this._.merge(this.gadgetSetting, this.queryModelDefaultSetting.dataInfo.gadgetSetting)
      var _self = this
      const params = {
        code: this.code,
        gadgettype: this.wgadgettype,
        widgetName: this.wName,
        gadgetId: this.id,
        includeSql: false
      }
      this.$interface.reports.getReportSettingInfo(params).then(({ data: res }) => {
        if (res.code !== 0) {
          return _self.$message.error(res.msg)
        }
        if (res.data) {
          _self._.merge(_self.gadgetSetting, res.data.gadgetSetting)
        }
        _self.resetslicer()
        _self.updateGadgetStatus('ready') //! IMPORTANT must have this code in every gadget
        _self.loading = false
      })
    }
  }
}
</script>
<style scoped>

</style>
